<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>抽象HTML艺术生成器</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #1a1a2e, #16213e);
            color: #fff;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            align-items: center;
            padding: 2rem;
            overflow-x: hidden;
        }
        
        header {
            text-align: center;
            margin-bottom: 2rem;
            max-width: 800px;
        }
        
        h1 {
            font-size: 3rem;
            margin-bottom: 0.5rem;
            background: linear-gradient(45deg, #ff6b6b, #4ecdc4, #45b7d1);
            -webkit-background-clip: text;
            background-clip: text;
            color: transparent;
            text-shadow: 0 2px 10px rgba(0,0,0,0.2);
        }
        
        .subtitle {
            font-size: 1.2rem;
            opacity: 0.8;
            margin-bottom: 1.5rem;
        }
        
        .controls {
            display: flex;
            flex-wrap: wrap;
            gap: 1rem;
            justify-content: center;
            margin-bottom: 2rem;
            background: rgba(255, 255, 255, 0.1);
            padding: 1.5rem;
            border-radius: 15px;
            backdrop-filter: blur(10px);
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
        }
        
        button {
            background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
            border: none;
            padding: 0.8rem 1.5rem;
            border-radius: 50px;
            color: white;
            font-weight: bold;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
        }
        
        button:hover {
            transform: translateY(-3px);
            box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
        }
        
        .art-container {
            width: 90%;
            max-width: 800px;
            height: 500px;
            background: rgba(0, 0, 0, 0.3);
            border-radius: 20px;
            overflow: hidden;
            position: relative;
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.4);
            margin-bottom: 2rem;
        }
        
        .abstract-art {
            width: 100%;
            height: 100%;
            display: grid;
            grid-template-columns: repeat(10, 1fr);
            grid-template-rows: repeat(10, 1fr);
            gap: 2px;
        }
        
        .cell {
            transition: all 0.5s ease;
            border-radius: 5px;
        }
        
        .particles {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            pointer-events: none;
        }
        
        .particle {
            position: absolute;
            width: 4px;
            height: 4px;
            border-radius: 50%;
            background: white;
            opacity: 0.7;
        }
        
        footer {
            margin-top: auto;
            text-align: center;
            opacity: 0.7;
            font-size: 0.9rem;
        }
        
        @media (max-width: 768px) {
            h1 {
                font-size: 2rem;
            }
            
            .art-container {
                height: 400px;
            }
        }
    </style>
</head>
<body>
    <header>
        <h1>抽象HTML艺术生成器</h1>
        <p class="subtitle">点击按钮生成独特的抽象图案，或与画布互动</p>
    </header>
    
    <div class="controls">
        <button id="generate">生成新图案</button>
        <button id="animate">切换动画</button>
        <button id="reset">重置</button>
    </div>
    
    <div class="art-container">
        <div class="abstract-art" id="art"></div>
        <div class="particles" id="particles"></div>
    </div>
    
    <footer>
        <p>使用纯HTML、CSS和JavaScript创建的抽象艺术 | 刷新页面获得全新体验</p>
    </footer>

    <script>
        // 初始化变量
        const artContainer = document.getElementById('art');
        const particlesContainer = document.getElementById('particles');
        const generateBtn = document.getElementById('generate');
        const animateBtn = document.getElementById('animate');
        const resetBtn = document.getElementById('reset');
        
        let isAnimating = false;
        let animationInterval;
        let particles = [];
        
        // 生成随机颜色
        function getRandomColor() {
            const hue = Math.floor(Math.random() * 360);
            return `hsl(${hue}, 70%, 60%)`;
        }
        
        // 生成随机渐变
        function getRandomGradient() {
            const color1 = getRandomColor();
            const color2 = getRandomColor();
            const angle = Math.floor(Math.random() * 360);
            return `linear-gradient(${angle}deg, ${color1}, ${color2})`;
        }
        
        // 生成抽象艺术
        function generateArt() {
            artContainer.innerHTML = '';
            
            for (let i = 0; i < 100; i++) {
                const cell = document.createElement('div');
                cell.className = 'cell';
                
                // 随机决定单元格样式
                const styleType = Math.random();
                
                if (styleType < 0.3) {
                    // 单色单元格
                    cell.style.background = getRandomColor();
                } else if (styleType < 0.6) {
                    // 渐变单元格
                    cell.style.background = getRandomGradient();
                } else if (styleType < 0.8) {
                    // 径向渐变
                    const color1 = getRandomColor();
                    const color2 = getRandomColor();
                    cell.style.background = `radial-gradient(circle, ${color1}, ${color2})`;
                } else {
                    // 透明单元格
                    cell.style.background = 'transparent';
                    cell.style.border = `2px solid ${getRandomColor()}`;
                }
                
                // 随机形状
                const shapeType = Math.random();
                if (shapeType < 0.3) {
                    cell.style.borderRadius = '50%';
                } else if (shapeType < 0.6) {
                    cell.style.borderRadius = '0';
                } else {
                    cell.style.borderRadius = '20%';
                }
                
                artContainer.appendChild(cell);
            }
        }
        
        // 创建粒子
        function createParticles() {
            particlesContainer.innerHTML = '';
            particles = [];
            
            for (let i = 0; i < 50; i++) {
                const particle = document.createElement('div');
                particle.className = 'particle';
                
                // 随机位置
                const x = Math.random() * 100;
                const y = Math.random() * 100;
                
                // 随机大小
                const size = Math.random() * 6 + 2;
                
                // 随机颜色
                particle.style.background = getRandomColor();
                
                // 随机动画
                const duration = Math.random() * 10 + 5;
                const delay = Math.random() * 5;
                
                particle.style.cssText = `
                    left: ${x}%;
                    top: ${y}%;
                    width: ${size}px;
                    height: ${size}px;
                    animation: float ${duration}s ease-in-out ${delay}s infinite alternate;
                `;
                
                particlesContainer.appendChild(particle);
                particles.push(particle);
            }
            
            // 添加浮动动画
            if (!document.getElementById('floatAnimation')) {
                const style = document.createElement('style');
                style.id = 'floatAnimation';
                style.textContent = `
                    @keyframes float {
                        0% {
                            transform: translate(0, 0) rotate(0deg);
                            opacity: 0.7;
                        }
                        50% {
                            opacity: 1;
                        }
                        100% {
                            transform: translate(${Math.random() * 100 - 50}px, ${Math.random() * 100 - 50}px) rotate(360deg);
                            opacity: 0.3;
                        }
                    }
                `;
                document.head.appendChild(style);
            }
        }
        
        // 切换动画
        function toggleAnimation() {
            isAnimating = !isAnimating;
            
            if (isAnimating) {
                animateBtn.textContent = '停止动画';
                startAnimation();
            } else {
                animateBtn.textContent = '开始动画';
                stopAnimation();
            }
        }
        
        // 开始动画
        function startAnimation() {
            animationInterval = setInterval(() => {
                const cells = document.querySelectorAll('.cell');
                cells.forEach(cell => {
                    // 随机变换
                    if (Math.random() > 0.7) {
                        cell.style.background = getRandomGradient();
                    }
                    
                    if (Math.random() > 0.9) {
                        cell.style.borderRadius = Math.random() > 0.5 ? '50%' : '0';
                    }
                    
                    // 轻微移动
                    cell.style.transform = `translate(${Math.random() * 10 - 5}px, ${Math.random() * 10 - 5}px)`;
                });
            }, 500);
        }
        
        // 停止动画
        function stopAnimation() {
            clearInterval(animationInterval);
            
            // 重置单元格位置
            const cells = document.querySelectorAll('.cell');
            cells.forEach(cell => {
                cell.style.transform = 'translate(0, 0)';
            });
        }
        
        // 重置画布
        function resetCanvas() {
            stopAnimation();
            isAnimating = false;
            animateBtn.textContent = '开始动画';
            generateArt();
            createParticles();
        }
        
        // 添加交互效果
        function addInteractivity() {
            artContainer.addEventListener('mouseover', (e) => {
                if (e.target.classList.contains('cell')) {
                    e.target.style.transform = 'scale(1.2)';
                    e.target.style.zIndex = '10';
                    e.target.style.boxShadow = '0 0 20px rgba(255,255,255,0.5)';
                }
            });
            
            artContainer.addEventListener('mouseout', (e) => {
                if (e.target.classList.contains('cell')) {
                    e.target.style.transform = 'scale(1)';
                    e.target.style.zIndex = '1';
                    e.target.style.boxShadow = 'none';
                }
            });
        }
        
        // 初始化
        function init() {
            generateArt();
            createParticles();
            addInteractivity();
            
            // 事件监听
            generateBtn.addEventListener('click', generateArt);
            animateBtn.addEventListener('click', toggleAnimation);
            resetBtn.addEventListener('click', resetCanvas);
        }
        
        // 页面加载时初始化
        window.addEventListener('DOMContentLoaded', init);
    </script>
</body>
</html>